//
//  LSZPartyViewController.m
//  PartyClassCloud
//
//  Created by 梁素珍 on 2018/8/14.
//  Copyright © 2018年 九酷. All rights reserved.
//

#import "LSZPartyViewController.h"

@interface LSZPartyViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property(nonatomic,strong) UICollectionView * collectionView;
//@property(nonatomic,strong) LSZLearningCatalogueManager * manager;
@property(nonatomic,strong) NSArray * arrayName;
@end

@implementation LSZPartyViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden=NO;
//    [LSZRequestDicData ihePartyInterface:^(BOOL isOk, NSString * string, LSZLearningCatalogueManager * manager) {
//        if (isOk == YES) {
//            self.manager = manager;
//            [self.collectionView reloadData];
//        }else{
//            AlertKuangView * alert = [AlertKuangView new];
//            [alert moveJingGaoKuang:string :self.view];
//        }
//    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"扶贫培训";
    self.arrayName = @[@"培训计划",@"培训课程",@"视频专题",@"在线考试"];
    //导航颜色和背景
    UINavigationBar * bar = self.navigationController.navigationBar;
    bar.barTintColor = themeColor;
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName : [UIFont fontWithName:@"Helvetica-Bold" size:22]}];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    UICollectionViewFlowLayout * flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.minimumInteritemSpacing = 0.5;
    flowLayout.minimumLineSpacing = 0.5;
    flowLayout.sectionInset = UIEdgeInsetsMake(0.5,0,0.5,0);//分别为上、左、下、右
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, ScreenWidth, ScreenHeight-NAVIGATION_BAR_HEIGHT) collectionViewLayout:flowLayout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.backgroundColor = RGBColor(236, 236, 236);
    //添加以下代码关闭估算行高
    [self.view addSubview:self.collectionView];
    [self.collectionView registerClass:[LSZPublicityFigureCollectionViewCell class] forCellWithReuseIdentifier:@"LSZPublicityFigureCollectionViewCell"];
    [self.collectionView registerClass:[LSZPartyCollectionViewCell class] forCellWithReuseIdentifier:@"LSZPartyCollectionViewCell"];
 }
#pragma mark <UICollectionViewDataSource>
#pragma mark - 设置有几个区
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
#pragma mark - 设置每个区有几个
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    // 定义的轮播器视图
    return 1+self.arrayName.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        LSZPublicityFigureCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZPublicityFigureCollectionViewCell" forIndexPath:indexPath];
        cell.imageViewBack.image = [UIImage imageNamed:@"党务bananer"];
        return cell;
    }else{
        LSZPartyCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LSZPartyCollectionViewCell" forIndexPath:indexPath];
        cell.labelTitle.text = NSStr(self.arrayName[indexPath.row-1]);
        cell.imageViewIcon.image = [UIImage imageNamed:NSStr(self.arrayName[indexPath.row-1])];
        return cell;
    }
}
#pragma mark - 点击进入详情页
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 1){
        LSZStudyPlanViewController * vc = [[LSZStudyPlanViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
//        if ([NullStringjudgment(NSStr([_UserM leaf])) isEqualToString:@"1"]) {
//            [self enterTheThreeSessionsOneLessonInterface];
//        }else{
//            LSZBigDepartmentVC * VC = [[LSZBigDepartmentVC alloc]init];
//            VC.specialMark = @"1";
//            VC.titleString = NullStringjudgment(NSStr([_UserM name]));
//            [self.navigationController pushViewController:VC animated:YES];
//        }
    }else if (indexPath.row == 2){
//        [self enterTheThreeSessionsOneLessonInterface];
        LSZLiteratureViewController * VC = [[LSZLiteratureViewController alloc]init];
        UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
        backItem.title=@"培训课程";
        self.navigationItem.backBarButtonItem = backItem;
        VC.comeStyle = @"2";
        [self.navigationController pushViewController:VC animated:YES];
//        LSZTheWalkmanViewController * vc = [[LSZTheWalkmanViewController alloc]init];
//        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
//        backItem.title = @"培训课程";
//        self.navigationItem.backBarButtonItem = backItem;
//        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 3){
        LSZVideoClassViewController * vc = [[LSZVideoClassViewController alloc]init];
        UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];
        backItem.title=@"视频专题";
        self.navigationItem.backBarButtonItem = backItem;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row == 4){
        LSZAnswerQuestionsViewController * VC = [[LSZAnswerQuestionsViewController alloc]init];
        [self.navigationController pushViewController:VC animated:YES];
    }else{
        LSZCalculatorViewController * vc = [[LSZCalculatorViewController alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
-(void)enterTheThreeSessionsOneLessonInterface
{
    if ([NullStringjudgment(NSStr([_MyCenter branch_id])) isEqualToString:@""]|| [NullStringjudgment(NSStr([_UserM summary])) isEqualToString:@""]) {
        [LSZRequestData initWithPersonalCenter:^(BOOL ISoK, NSString * str, NSDictionary * dic) {
            if (ISoK == YES) {
                LSZParentThreeLessonVC * VC= [[LSZParentThreeLessonVC alloc]init];
                VC.id_id = [_MyCenter branch_id];
                VC.summary = [_MyCenter my_summary];
                UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
                backItem.title = @"三会一课";
                self.navigationItem.backBarButtonItem = backItem;
                [self.navigationController pushViewController:VC animated:YES];
            }
        }];
    }else{
        LSZParentThreeLessonVC * VC= [[LSZParentThreeLessonVC alloc]init];
        VC.id_id = [_MyCenter branch_id];
        VC.summary = [_UserM summary];
        UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
        backItem.title = @"三会一课";
        self.navigationItem.backBarButtonItem = backItem;
        [self.navigationController pushViewController:VC animated:YES];
    }
}
#pragma mark - cell大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    if (indexPath.row == 0) {
        return CGSizeMake(ScreenWidth, 200);
    }else{
        CGFloat width = (ScreenWidth -2) / 4;
        return CGSizeMake(width, width);
    }
}


@end
